package com.lagou.homework1_3;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class WorkerListTest {

    public static void main(String[] args) {
        //(2)定义List集合，在List集合中增加三个员工，基本信息如下：  "凤姐" 18 20000  "欧阳峰" 60 8000  "刘德华" 40 30000
        List<Worker> list = new LinkedList<>();
        Worker oyf = new Worker("欧阳峰",60,8000);
        Worker ldh = new Worker("刘德华",40,30000);

        list.add(new Worker("凤姐",18,20000));
        list.add(oyf);
        list.add(ldh);

        //查找欧阳锋所在索引
        int i = list.indexOf(oyf);
        //(3)在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        list.add(i,new Worker("张柏芝",35,30000));

        //(4)删除"刘德华"的信息
        list.remove(ldh);

        //(5)利用for 循环遍历，打印List 中所有员工的信息
        for (Worker w: list) {
            System.out.println(w);
        }

        System.out.println("------------------------------------");

        //(6)利用迭代遍历，对List 中所有的员工调用work 方法
        Iterator<Worker> it = list.iterator();
        while (it.hasNext()){
            Worker w = it.next();
            w.work();
        }
    }
}
